const db = require('../../db')

const video = 'video'

const router = require('express').Router()



router.get(`/${video}`, (req, res) => {
  let pagenum = req.query.pagenum
  let pagesize = req.query.pagesize
  // // 翻页
  let offset = (pagenum - 1) * pagesize

  let sql = `select * from video order by v_id limit ${offset},${pagesize};select count(*) total from video`
  db.query(sql, (error, result, fields) => {
    if (error) {
      res.json({
        'code': 201,
        'error': '查询出错'
      })
    } else {
      res.json({
        'code': 200,
        'data': result[0],
        'total': result[1][0].total
      })
      // console.log(result);
    }
  })
})

router.get('/title', (req, res) => {
  let sql = `select title from ebook where title like 'SAP PA教材%' limit 0,15`
  db.query(sql, (error, result, fields) => {
    if (error) {
      res.json({
        'code': 400
      })
    } else {
      res.json({
        'code': 200,
        'data': result
      })
      // console.log(result);
    }
  })
})


module.exports = router